﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MsBuild = Microsoft.Build.Evaluation;
using System.IO;
using Genuilder.Extensibility;

namespace Genuilder
{
	public class TargetFeature : Feature
	{
		readonly string _Path;
		public TargetFeature(string path)
		{
			if(path == null)
				throw new ArgumentNullException("path");
			if(path == String.Empty)
				throw new ArgumentException("path cannot be empty");
			_Path = path;
			if(!File.Exists(path))
			{
				throw new FileNotFoundException("Target " + path + " not found");
			}
		}
		public override void LoadFeature(Project project, MSBuildData msBuildData)
		{
			var importPath = PathUtil.RelativePathTo(new FileInfo(project.Path).Directory.FullName, new FileInfo(_Path).FullName);
			msBuildData.ProjectRootElement.AddImport(importPath).After(msBuildData.StartImportGenuilder);
		}
	}
}
